#include <iostream>
#include <vector>

using namespace std;

int main()
{
    string g;
    getline(cin, g);
    vector<string> a;
    int pos = 0;
    string s;
    while ((pos = g.find(' ')) != -1)
    {
        s = g.substr(0, pos);
        a.push_back(s);
        g.erase(0, pos + 1);
    }
    a.push_back(g);
    string k = "";
    int f = 0;
    for (string e : a)
    {
        if (e == "one")
        {
            k += "1";
        }
        else if (e == "two")
        {
            k += "2";
        }
        else if (e == "three")
        {
            k += "3";
        }
        else if (e == "four")
        {
            k += "4";
        }
        else if (e == "five")
        {
            k += "5";
        }
        else if (e == "six")
        {
            k += "6";
        }
        else if (e == "seven")
        {
            k += "7";
        }
        else if (e == "eight")
        {
            k += "8";
        }
        else if (e == "nine")
        {
            k += "9";
        }
        else if (e == "zero")
        {
            k += "0";
        }
        else
        {
            cout << "Wrong input" << endl;
            f = 1;
            break;
        }
    }

    if (f == 0)
    {
        int n = stoi(k);
        int t = n + 1;
        vector<int> b, c;
        for (int i = 2; i < n; i++)
        {
            for (int j = 2; j < i; j++)
            {
                if (i % j == 0)
                {
                    b.push_back(j);
                }
            }
            if (b.size() > 0)
            {
                b.clear();
                continue;
            }
            else
            {
                c.push_back(i);
                continue;
            }
        }
        vector<int> d, h;
        while (h.empty())
        {
            for (int j = 2; j < t; j++)
            {
                if (t % j == 0)
                {
                    d.push_back(j);
                }
            }
            if (d.size() > 0)
            {
                d.clear();
                t++;
                continue;
            }
            else
            {
                h.push_back(t);
                break;
            }
        }
        if (n - c.back() > h[0] - n)
        {
            cout << h[0] << endl;
        }
        else
        {
            cout << c.back() << endl;
        }
    }
}
